package com.android.appsoma;



import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;
import android.app.*;

public class AppSoma extends Activity {
    /** Called when the activity is first created. */
	EditText ednum1, ednum2, edres;
	private static final String[] percentual = {"+","-","X","%"};
	ArrayAdapter<String> aOperacao;
	Spinner spnsop;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ednum1 = (EditText) findViewById(R.campo.num1);
        ednum2 = (EditText) findViewById(R.campo.num2);
        edres = (EditText) findViewById(R.campo.res);
        Button btMostrar = (Button) findViewById(R.botao.btmostrar);
        
        aOperacao = new  	ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,percentual);
    	spnsop = (Spinner) findViewById(R.opcao.spnopcao);
    	spnsop.setAdapter(aOperacao);
        
        btMostrar.setOnClickListener(new View.OnClickListener(){
        	public void onClick(View arg0) {
        	double num1 = Double.parseDouble(ednum1.getText().toString());
        	double num2 = Double.parseDouble(ednum2.getText().toString());
        	double res=0;
        	
        	switch(spnsop.getSelectedItemPosition()) {
        	case 0: res = (num1 + num2); break;
        	case 1: res = (num1 - num2); break;
        	case 2: res = (num1 * num2); break;
        	case 3: res = (num1 / num2);break;}
        	
        	edres.setText(String.valueOf(res));
        	
        	}
        	});
        }
    
}